﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Yipusoft.Account.BLL;
using Yipusoft.Account.Model;
using System.Collections.Generic;

public partial class Task_Task : System.Web.UI.MasterPage
{
    private List<MenuInfo> menus;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["RootMenuID"] != null)
            {
                Session["RootMenuID"] = Request.QueryString["RootMenuID"];
            }
            menus = Yipusoft.Account.BLL.User.GetMenuList(Context.User.Identity.Name);
            ModelTitle.Text = Yipusoft.Account.BLL.Menu.GetMenu(Session["RootMenuID"].ToString()).MenuName;
            SideMenu.Items.Clear();
            BindMenu(SideMenu.Items, Session["RootMenuID"].ToString());
        }
    }
    private void BindMenu(MenuItemCollection items, string parentID)
    {
        MenuItem item;
        foreach (MenuInfo menu in menus)
        {
            if (menu.ParentID == parentID)
            {
                item = new MenuItem();
                if (menu.MenuImage == "")
                {
                    item.ImageUrl = "../images/icons/icon_blank.gif";
                }
                else
                {
                    item.ImageUrl = "../images/icons/" + menu.MenuImage;
                }
                item.Text = menu.MenuName;
                if (menu.MenuUrl != "")
                {
                    item.NavigateUrl = menu.MenuUrl;
                }
                else
                {
                    item.NavigateUrl = "#";
                }
                if (menu.IsBlank)
                {
                    item.Target = "_blank";
                }
                item.ToolTip = menu.Description;
                items.Add(item);
                BindMenu(item.ChildItems, menu.MenuID);
            }
        }
    }
}
